<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns result set metadata from a prepared statement</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.maxdb-stmt-result-metadata" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">maxdb_stmt_result_metadata</h1>
  <h1 class="refname">maxdb_stmt::result_metadata</h1>
  <p class="verinfo">(PECL maxdb &gt;= 1.0)</p><p class="refpurpose"><span class="refname">maxdb_stmt_result_metadata</span> -- <span class="refname">maxdb_stmt::result_metadata</span> &mdash; <span class="dc-title">Returns result set metadata from a prepared statement</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.maxdb-stmt-result-metadata-description">
  <h3 class="title">说明</h3>
  <p class="para">过程化风格</p>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>maxdb_stmt_result_metadata</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
   ) : <span class="type">resource</span></div>

  <p class="para rdfs-comment">面向对象风格</p>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>maxdb_stmt::result_metadata</strong></span>
    ( <span class="methodparam">void</span>
   ) : <span class="type">resource</span></div>

  <p class="para rdfs-comment">
   If a statement passed to <span class="function"><a href="maxdb_prepare.html" class="function">maxdb_prepare()</a></span> is one that produces
   a result set, <span class="function"><strong>maxdb_stmt_result_metadata()</strong></span> returns the result resource
   that can be used to process the meta information such as total number of fields
   and individual field information.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">This result set pointer can be passed as an argument to any of the
    field-based functions that process result set metadata, such as:
    <ul class="itemizedlist">
     <li class="listitem"><p class="para"><span class="function"><a href="maxdb_num_fields.html" class="function">maxdb_num_fields()</a></span></p></li>
     <li class="listitem"><p class="para"><span class="function"><a href="maxdb_fetch_field.html" class="function">maxdb_fetch_field()</a></span></p></li>
     <li class="listitem"><p class="para"><span class="function"><a href="maxdb_fetch_field_direct.html" class="function">maxdb_fetch_field_direct()</a></span></p></li>
     <li class="listitem"><p class="para"><span class="function"><a href="maxdb_fetch_fields.html" class="function">maxdb_fetch_fields()</a></span></p></li>
     <li class="listitem"><p class="para"><span class="function"><a href="maxdb_field_count.html" class="function">maxdb_field_count()</a></span></p></li>
     <li class="listitem"><p class="para"><span class="function"><a href="maxdb_field_seek.html" class="function">maxdb_field_seek()</a></span></p></li>
     <li class="listitem"><p class="para"><span class="function"><a href="maxdb_field_tell.html" class="function">maxdb_field_tell()</a></span></p></li>
     <li class="listitem"><p class="para"><span class="function"><a href="maxdb_free_result.html" class="function">maxdb_free_result()</a></span></p></li>
    </ul>
   </p>
  </p></blockquote>
  <p class="para">
   The result set structure should be freed when you are done with it,
   which you can do by passing it to <span class="function"><a href="maxdb_free_result.html" class="function">maxdb_free_result()</a></span>
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    The result set returned by <span class="function"><strong>maxdb_stmt_result_metadata()</strong></span> contains only
    metadata. It does not contain any row results. The rows are obtained by using the
    statement handle with <span class="function"><a href="maxdb_fetch.html" class="function">maxdb_fetch()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.maxdb-stmt-result-metadata-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>maxdb_stmt_result_metadata()</strong></span> returns a result resource or <strong><code>FALSE</code></strong> if
   an error occurred.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.maxdb-stmt-result-metadata-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1431">
    <p><strong>Example #1 面向对象风格</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$maxdb&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">maxdb</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"MONA"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"RED"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DEMODB"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;temp.friends&nbsp;(id&nbsp;int,&nbsp;name&nbsp;varchar(20))"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;temp.friends&nbsp;VALUES&nbsp;(1,'Hartmut')"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;temp.friends&nbsp;VALUES&nbsp;(2,&nbsp;'Ulf')"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;id,&nbsp;name&nbsp;FROM&nbsp;temp.friends"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;get&nbsp;resultset&nbsp;for&nbsp;metadata&nbsp;*/<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">result_metadata</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;retrieve&nbsp;field&nbsp;information&nbsp;from&nbsp;metadata&nbsp;result&nbsp;set&nbsp;*/<br /></span><span style="color: #0000BB">$field&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_field</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Fieldname:&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$field</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;close&nbsp;resultset&nbsp;*/<br /></span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;close&nbsp;connection&nbsp;*/<br /></span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
   <div class="example" id="example-1432">
    <p><strong>Example #2 过程化风格</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">maxdb_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"MONA"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"RED"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DEMODB"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">maxdb_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;temp.friends&nbsp;(id&nbsp;int,&nbsp;name&nbsp;varchar(20))"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">maxdb_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;temp.friends&nbsp;VALUES&nbsp;(1,'Hartmut')"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">maxdb_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;temp.friends&nbsp;VALUES&nbsp;(2,&nbsp;'Ulf')"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">maxdb_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;id,&nbsp;name&nbsp;FROM&nbsp;temp.friends"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">maxdb_stmt_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;get&nbsp;resultset&nbsp;for&nbsp;metadata&nbsp;*/<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">maxdb_stmt_result_metadata</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;retrieve&nbsp;field&nbsp;information&nbsp;from&nbsp;metadata&nbsp;result&nbsp;set&nbsp;*/<br /></span><span style="color: #0000BB">$field&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">maxdb_fetch_field</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Fieldname:&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$field</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;close&nbsp;resultset&nbsp;*/<br /></span><span style="color: #0000BB">maxdb_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;close&nbsp;connection&nbsp;*/<br /></span><span style="color: #0000BB">maxdb_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">以上例程的输出类似于：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
Fieldname: ID
</pre></div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.maxdb-stmt-result-metadata-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="maxdb_prepare.html" class="function" rel="rdfs-seeAlso">maxdb_prepare()</a> - Prepare an SQL statement for execution</span></li>
    <li class="member"><span class="function"><a href="maxdb_free_result.html" class="function" rel="rdfs-seeAlso">maxdb_free_result()</a> - Frees the memory associated with a result</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>